<template>
  <form-item-setting v-model:config="config">
    <a-form-item
      field="defaultValue"
      tooltip=""
      label="默认值"
      :allow-clear="true"
    >
      <a-select
        v-model="config.config.defaultValue"
        allow-clear
        :multiple="config.config.multiple"
        :limit="config.config.limit"
      >
        <a-option
          v-for="item of roleList"
          :key="item.roleId"
          :value="item.roleId"
          :tag-props="{color: 'blue'}"
        >
          {{ item.roleName }}
        </a-option>
      </a-select>
    </a-form-item>
    <a-form-item
      field="placeholder"
      tooltip=""
      label="提示文字"
    >
      <a-input v-model="config.config.placeholder" allow-clear />
    </a-form-item>
    <a-form-item
      field="multiple"
      tooltip=""
      label="是否多选"
    >
      <a-switch
        v-model="config.config.multiple"
        type="round"
      >
        <template #checked>
          多选
        </template>
        <template #unchecked>
          单选
        </template>
      </a-switch>
    </a-form-item>
    <a-form-item
      field="limit"
      tooltip="多选时最多的选择个数"
      label="最多选项"
    >
      <a-input-number
        v-model="config.config.limit"
        mode="button"
        allow-clear
      />
    </a-form-item>
    <a-form-item
      field="maxTagCount"
      tooltip="多选模式下，最多显示的标签数量。0 表示不限制"
      label="标签数量"
    >
      <a-input-number
        v-model="config.config.maxTagCount"
        mode="button"
        allow-clear
      />
    </a-form-item>
    <a-form-item
      field="allowSearch"
      tooltip=""
      label="允许搜索"
    >
      <a-switch
        v-model="config.config.allowSearch"
        type="round"
      >
        <template #checked>
          允许
        </template>
        <template #unchecked>
          不允许
        </template>
      </a-switch>
    </a-form-item>
    <a-form-item
      field="bordered"
      tooltip="是否显示输入框的边框"
      label="显示边框"
    >
      <a-switch
        v-model="config.config.bordered"
        type="round"
      >
        <template #checked>
          是
        </template>
        <template #unchecked>
          否
        </template>
      </a-switch>
    </a-form-item>
    <a-form-item
      field="allowClear"
      tooltip="是否允许清空输入框"
      label="允许清空"
    >
      <a-switch
        v-model="config.config.allowClear"
        type="round"
      >
        <template #checked>
          允许
        </template>
        <template #unchecked>
          不允许
        </template>
      </a-switch>
    </a-form-item>
    <a-divider style="border-bottom-style: dotted" orientation="center" :size="2" :margin="0">
      事件设置
    </a-divider>
    <br />
    <a-form-item
      field="onChangeFunction"
      tooltip=""
      label="Change"
    >
      <a-button
        type="primary"
        shape="round"
        @click="editOnChange"
      >
        <template #icon>
          <icon-edit />
        </template>
        编辑事件
      </a-button>
      <code-editor
        ref="codeEditorRef"
        v-model:code="config.config.onChangeFunction"
      />
    </a-form-item>
  </form-item-setting>
</template>

<script lang="ts" setup>
import { ref, defineModel, onMounted } from 'vue';
import { roleSelect } from '@/api/system/role';
import FormItemSetting from '@/components/form-design/item-setting/form-item-setting.vue';
import CodeEditor from '@/components/code-editor/index.vue';

const config = defineModel('config', { type: Object, default: {} });

const roleList = ref();

const codeEditorRef = ref();

const editOnChange = () => {
  codeEditorRef.value.open();
};

onMounted(() => {
  roleSelect().then(res => {
    roleList.value = res.data;
  });
});
</script>

<script lang="ts">
export default {
  name: 'ItemSettingRoleSelect'
};
</script>

<style scoped>

</style>